<!--
 * @Author: ChunLai
 * @Date: 2021-10-18 11:39:34
 * @LastEditTime: 2025-07-28 10:06:09
 * @Description: 验证码输入框
 * @FilePath: \02.bldinsure\src\views\pay\components\SmsCodeInput.vue
-->
<template>
  <div class="smscode_valid_mode">
    <van-overlay :show="dialogPop" z-index="100">
      <div class="wrappers">
        <ul class="md-ul">
          <li class="mode_tt">手机验证码</li>
          <li class="md-li">
            <span class="md-li-span">手机号</span>
            <span> {{ phone | formatPhone }} </span>
          </li>
          <li class="md-li2">
            <van-field
              label="短信验证"
              v-model="verfyCode"
              maxlength="6"
              :error-message="errMsg"
              placeholder="请输入短信验证码"
            >
            </van-field>
          </li>
          <li class="md-li-btn">
            <span class="btn-span" @click="handleSure(vm)">确认</span>
          </li>
        </ul>
      </div>
    </van-overlay>
  </div>
</template>

<script>
import { debounce } from '@/utils/debounce';

export default {
  name: 'SmsCodeInput',
  data() {
    return {
      errMsg: '',
      verfyCode: '', // 验证码
      CountDown: '发送验证码',
      vm: this,
      phone: '',
      dialogPop: false,
    };
  },
  filters: {
    formatPhone(val) {
      return val.substring(0, 3) + ' **** ' + val.substring(7);
    },
  },
  methods: {
    initModule(phone) {
      this.phone = phone;
      this.dialogPop = true;
    },
    handleSure: debounce(
      (vm) => {
        if (vm.verfyCode === '') {
          vm.errMsg = '请输入验证码';
          return false;
        }
        vm.errMsg = '';
        vm.dialogPop = false;
        vm.$emit('handleCheck', '01', vm.verfyCode);
      },
      1000,
      true
    ),
  },
};
</script>

<style lang="less" scoped>
.mode_tt {
  text-align: center;
  font-size: 16px;
  margin-bottom: 10px;
}
.wrappers {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding-bottom: 60px;
}
.md-ul {
  padding: 20px 20px 10px;
  background-color: #fff;
  width: 85%;
  border-radius: 10px;
}
.md-li {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #e8e8e8;
  .md-li-span {
    width: 86px;
    color: #646566;
  }
}
.md-li-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 60px;
  margin-top: 15px;
  .btn-span {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50%;
    height: 36px;
    color: #fff;
    border-radius: 4px;
    background-color: #f56c6c;
    border-color: #f56c6c;
    font-size: 14px;
    &:active {
      opacity: 0.7;
    }
  }
}

.smscode_valid_mode {
  /deep/ .van-cell {
    padding: 10px 0;
  }
  /deep/ .van-field__label {
    margin-right: 0;
  }
}
</style>
